from flask import Flask, render_template, Response,request,jsonify
import subprocess
from frameworks.utils.JsonResult2 import *
import json

app = Flask(__name__)

@app.route('/cmd',methods=['POST'])
def index():
    jsonrs = JsonResult2()
    cmd = request.get_data(as_text=True)
    if cmd != "":
        result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    else:
        result = "执行命令"
    data = []
    data.append(str(result.stdout,encoding='utf-8'))
    return jsonrs.setOk(data)


if __name__ == '__main__':
    app.run()
